from config import BASE_URL
from common import get_token,loggin_config
logger=loggin_config.get_logger()
import requests

class Autometer_Project():
    #创建项目
    def add_project(self,data):
        url=BASE_URL+"/project"
        headers={
            "Content-Type":"application/json;charset=UTF-8",
            "Authorization": get_token.Autometer_login_token()
        }
        resp=requests.post(url,headers=headers,json=data)
        logger.info(f"添加项目{resp.json()}")
        return resp

    # 获取项目列表
    def get_project_list(self,data):
        url=BASE_URL+"/project/search"
        headers={
            "Content-Type":"application/json;charset=UTF-8",
            "Authorization":get_token.Autometer_login_token()
        }
        resp=requests.post(url,headers=headers,json=data)
        logger.info(f"获取项目列表{resp.json()}")
        return resp

    #修改项目
    def updata_project(self,data):
        url=BASE_URL+"/project/detail"
        headers={
            "Content-Type":"application/json;charset=UTF-8",
            "Authorization":get_token.Autometer_login_token()
        }
        resp=requests.put(url,headers=headers,json=data)
        logger.info(f"修改项目{resp.json()}")
        return resp

    #选择添加成员列表
    def get_member_list(self,data):
        url=BASE_URL+"/account/searchaccount"
        headers={
            "Content-Type":"application/json;charset=UTF-8",
            "Authorization":get_token.Autometer_login_token()
        }
        resp=requests.post(url,headers=headers,json=data)
        logger.info(f"获取成员列表{resp.json()}")
        return resp

    #添加成员
    def add_member(self,data):
        url=BASE_URL+"/project/account/addprojectaccounts"
        headers={
            "Content-Type":"application/json;charset=UTF-8",
            "Authorization":get_token.Autometer_login_token()
        }
        resp=requests.post(url,headers=headers,json=data)
        logger.info(f"添加成员{resp.json()}")
        return resp
    
    #查询成员   
    def query_member(self,data):
        url=BASE_URL+"/account/searchaccount"
        headers={
            "Content-Type":"application/json;charset=UTF-8",
            "Authorization":get_token.Autometer_login_token()
        }
        resp=requests.post(url,headers=headers,json=data)
        logger.info(f"查询成员{resp.json()}")

    #删除项目成员
    def delete_project_member(self, data):
        url = BASE_URL + "/project/account/findaccountbyprojectid"
        headers = {
            "Content-Type": "application/json;charset=UTF-8",
            "Authorization": get_token.Autometer_login_token()
        }
        resp = requests.post(url, headers=headers, json=data)
        logger.info(f"删除项目成员{resp.json()}")

    #项目查询
    def select_project(self, data):
        url = BASE_URL + "/project/search"
        headers = {
            "Content-Type": "application/json;charset=UTF-8",
            "Authorization": get_token.Autometer_login_token()
        }
        resp = requests.post(url, headers=headers, json=data)
        logger.info(f"根据项目状态查询{resp.json()}")


if __name__=="__main__":
    dome=Autometer_Project()
    # data={"page":1,"size":10,"projectname":"","status":None}
    # dome.get_project_list(data)
    # data={"id":"","projectname":"test12345","status":"关闭","startTime":"","endTime":"","memo":"asd","creator":"test"}
    # dome.add_project(data)
    # data={"id":983,"projectname":"test123","status":"开始","startTime":1714722351000,"endTime":1714722351000,"memo":"asd","creator":"test"}
    # dome.updata_project(data)
    # data={"page":1,"size":10,"nickname":None}
    # dome.get_member_list(data)
    # data=[{"projectid":983,"accountid":4,"projectname":"test123","nickname":"管理员","creator":"test"}]
    # dome.add_member(data)
    # data={"page":1,"size":10,"nickname":"test"}
    # dome.query_member(data)
    # data={"page":1,"size":10,"projectid":983,"projectname":"test123","status":None}
    # dome.delete_project_member(data)
    # data={"page":1,"size":10,"projectname":"","status":"暂停"}
    # dome.select_project(data)